package com.demo1107.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo1107/demo02.do")
public class Demo02Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        //        data: {name: "张三", age: 18},
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        System.out.println("name = " + name);
        System.out.println("age = " + age);
        //给前端回传数据 回传的数据 会出现在success回调函数的data中
        resp.getWriter().write("这是后端传来的字符串");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
